<template>
  <div class="common-page en-audit-page">
    <SearchForm
      :search-list="searchList"
      :search-params="searchParams"
      @search="onSearch"
      @reset="onReset"
    />
    <el-form>
      <el-form-item>
        <div
          class="f-r a-c j-e"
        >
          <el-button type="primary" style="margin-left: 15px" @click="onAdd">添加</el-button>
        </div>
      </el-form-item>
    </el-form>
    <div class="table-box">
      <el-table
        v-loading="loading"
        height="100%"
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
        <el-table-column label="状态">
          <template slot-scope="scope">
            <AuditStatusTag :status="scope.row.state" :status-list="statusList" />
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="160px">
          <template slot-scope="scope">
            <el-button type="primary" @click="onEdit(scope.row)">编辑</el-button>
            <el-button type="danger" @click="onDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
    <Add ref="addFormRef" @get-page="onSearch" />
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import Add from './add'
import { http } from '@/api'
export default {
  name: 'Index',
  components: {
    Add
  },
  mixins: [crud],
  data() {
    return {
      request: http.enterprise,
      searchList: [
        {
          key: 'enterpriseName',
          name: 'input',
          label: '企业名称'
        },
        {
          key: 'enterpriseType',
          name: 'input',
          label: '企业类型'
        }
      ],
      searchParams: {
        enterpriseName: '',
        enterpriseType: ''
      },
      columns: [
        { prop: 'enterpriseName', label: '企业名称' },
        { prop: 'enterpriseType', label: '企业类型' },
        { prop: 'createTime', label: '创建时间' },
        { prop: 'enterpriseDirector', label: '企业负责人' },
        { prop: 'enterprisePhone', label: '联系方式' }
      ],
      tableData: [

      ],
      statusList: [
          { value: '0', name: '待审核' },
          { value: '1', name: '已通过' },
        { value: '2', name: '已拒绝' }
      ]
    }
  },
  created() {
    this.request.categoryList().then(res => {
      this.searchList[0].options = res.data.map(el => {
        return {
          value: el,
          name: el
        }
      })
    })
  },
  methods: {
    onEdit(item) {
      this.$refs.addFormRef.open(item, this.searchList[0].options)
    }
  }
}
</script>

<style lang="scss">
.en-audit-page {
    .tag0 {
        color: #15C521;
        background: #DDFFDE;
        border: 1px solid #15C521;
    }
    .tag1 {
        color: #F82222;
        background: #ffe2e2;
        border: 1px solid #F82222;
    }
}
</style>
